package com.dykj.apps.web.sysmanager.dao;

import java.util.ArrayList;
import java.util.List;

import com.dykj.apps.web.sysmanager.dto.SysRoleDTO;
import com.dykj.platform.framework.common.paging.Hquery;
import com.dykj.platform.framework.common.paging.Page;
import com.dykj.platform.framework.common.paging.PagingHelper;
import com.dykj.platform.framework.exception.DatabaseException;
import com.dykj.platform.framework.common.paging.AbstractPQDAO;

public class RoleManagerDAOImpl extends AbstractPQDAO implements IRoleManagerDAO {

	private static final long serialVersionUID = 1L;

	public Hquery createHQ(Object objDTO, Page page) throws DatabaseException {
		SysRoleDTO dto = (SysRoleDTO)objDTO;
		Hquery hquery = new Hquery();
		List paramlist = new ArrayList();
		StringBuffer strBufHql = new StringBuffer();
		strBufHql.append("from SysRole r where 1=1 ");
		//部门
		strBufHql.append(PagingHelper.createWherePara("and","r.roledesc","like",dto.getP_roledesc(),paramlist));
		//创建人
		strBufHql.append(PagingHelper.createWherePara("and","r.creator","=",dto.getCreator(),paramlist));
		hquery.setParalist(paramlist);
		hquery.setQueryString(strBufHql.toString());
		if(page.getSort()!=null){
			hquery.setSortOrder(page.getSort().getSortOrder());
			hquery.setOrderby(page.getSort().getProperty());
		}
		return hquery;
	}

	public List queryAllRole(String creator) throws DatabaseException {
		String hql = "from SysRole s";
		if(null!=creator){
			hql = hql+" where s.creator ='"+creator+"'";
		}
		return this.query(hql);
	}

	public List queryBydesc(String roledesc, String roleid ,String creator) throws DatabaseException {
		String hql = "from SysRole s where s.creator = '"+ creator +"'";
		hql = hql + "and s.roledesc = '"+ roledesc +"'";
		if(roleid!=null && !"".equals(roleid)){
			hql=hql+"and s.roleid <> '"+ roleid +"'";
		}
		return this.query(hql);
	}
}
